# # 假设有一个字典`person_info` 储存了一个人的信息，包含不少于5个键值对
# person_info = {
#     "name": "Alex",
#     "age": 30,
#     "country": "USA",
#     "language": ["English", "Spanish"],
#     "is_student": False
# }
# # 打印`person_info` 字典的`name` 值
# print(person_info['name'])
# # 修改`age` 的值为 31
# person_info['age'] = 31
# print(person_info)
# # 向字典中添加一个新的键值对 `height": 175`
# person_info.update({'height':175})
# print(person_info)
# # 删除字典中的 `is_student"` 键及其值
# del person_info['is_student']
# print(person_info)
# # 使用循环遍历字典，打印所有的键和值
# for i in person_info.items():
#     print(i)
# # 检查字典中是否有 `email"` 这个键，如果没有，添加 `email": "alex@example.com"
# if 'email' not in person_info:
#     person_info.update({'email': 'alex@example.com'})
#     print('no')
# else:
#     print('yes')
# print(person_info)
# # 将`language` 的值改为只包含 `English"`
# person_info.update({'language':'English'})
# print(person_info)
# # 获取并打印字典中`language` 列表的长度
# language_list = person_info['language']
# print(len(language_list))
# # 向`language` 列表中添加一种新语言 `French"
# person_info['language'] = [person_info['language']]
# person_info['language'].append("French")
# print(person_info)
# # 循环插入新的键值对到字典：将 ` hobby'` + 数字 作为键，相应的 ` hobby'` + 数字值 作为值，数字从1至3
# n = 1
# while n <= 3:
#     key = f'hobby{n}'
#     vaule = f'hobby{n}'
#     n+=1
#     person_info.update({key:vaule})
# print(person_info)

employees = {
    101: {
        "name": "Alice",
        "age": 30,
        "gender": "Female",
        "position": "Data Scientist",
        "team": "Research",
        "salary_history": [70000, 80000, 90000]
    },
    # 更多员工数据...
}
# 新增一个员工的信息到`employees`字典中
id = 102
infor = {
        "name": "Mike",
        "age": 20,
        "gender": "male",
        "position": "python Scientist",
        "team": "HR",
        "salary_history": [50000, 55000, 60000]
    }
employees[id] = infor
print(employees)
# 删除一个指定的员工的信息
del employees[102]
print(employees)
# 更新员工101的年龄至31
employees[101]['age'] = 31
print(employees)
# 增加员工101薪资历史中的最新薪资至95000
salary = employees[101]['salary_history']
salary.append(95000)
print(employees)
# 计算员工101的平均薪资
n=0
count = 0
for i in employees[101]['salary_history']:
    count = i+count
    n+=1
num = count/n
print(num)
# 找出所有年龄大于25岁的员工的姓名和ID
for emp_id,emp_info in employees.items():
    if emp_info['age'] > 25:
        print(f"ID: {emp_id}, Name: {emp_info['name']}")
# 对`employees`中的每个员工，添加'bonus'键至其字典中，其中值是最新薪资的10%
for emp_id,emp_info in employees.items():
    salary_bonus = emp_info['salary_history'][-1]
    bonus =salary_bonus*0.1
    emp_info['bonus'] = bonus
print(employees)
# 将员工101的职位更新为"Senior Data Scientist"
employees[101]['position'] = 'Senior Data Scientist'
print(employees)
# 从员工的信息中移除`gender`键
for i in employees.values():
    del i['gender']
print(employees)
# 创建一个新的嵌套字典，该字典仅包含员工的`name`和`position`
new = {}
for emp_id,emp_info in employees.items():
    new_name = emp_info['name']
    new_position = emp_info['position']
    new.update({'name':new_name,'position':new_position})
print(new)
# new = {emp_id: {k: v for k, v in emp_info.items() if k in ['name', 'position']}
#        for emp_id, emp_info in employees.items()}
# print(new)